# coding=utf-8
import numpy as np
import pandas as pd
import time


# 天气特征的处理
def climate_to_onehot(data):
    #data = pd.read_csv('./data/data_count/order_' + day, index_col=[0])
    climate_clear = []
    climate_partlycloudy = []
    climate_scatteredclouds = []
    climate_mostlycloudy = []
    climate_lightrainshowers = []
    climate_lightrain = []
    climate_unknown = []
    climate_overcast = []
    climate_rain = []
    climate_rainshowers = []
    climate_thunderstorm = []
    climate_lightthunderstorms = []
    climate_heavyrain  = []
    for item in data['天气描述']:
        climate_clear.append(judge_climate(item, 0))
        climate_partlycloudy.append(judge_climate(item, 1))
        climate_scatteredclouds.append(judge_climate(item, 2))
        climate_mostlycloudy.append(judge_climate(item, 3))
        climate_lightrainshowers.append(judge_climate(item, 4))
        climate_lightrain.append(judge_climate(item, 5))
        climate_unknown.append(judge_climate(item, 6))
        climate_overcast.append(judge_climate(item, 7))
        climate_rain.append(judge_climate(item, 8))
        climate_rainshowers.append(judge_climate(item, 9))
        climate_thunderstorm.append(judge_climate(item, 10))
        climate_lightthunderstorms.append(judge_climate(item, 11))
        climate_heavyrain.append(judge_climate(item, 12))

    data = data.drop(['天气描述','天气记录'], axis=1)
    data['climate_clear'] = climate_clear
    data['climate_partlycloudy'] = climate_partlycloudy
    data['climate_scatteredclouds'] = climate_scatteredclouds
    data['climate_mostlycloudy'] = climate_mostlycloudy
    data['climate_lightrainshowers'] = climate_lightrainshowers
    data['climate_lightrain'] = climate_lightrain
    data['climate_unknown'] = climate_unknown
    data['climate_overcast'] = climate_overcast
    data['climate_rain'] = climate_rain
    data['climate_rainshowers'] = climate_rainshowers
    data['climate_thunderstorm'] = climate_thunderstorm
    data['climate_lightthunderstorms'] = climate_lightthunderstorms
    data['climate_heavyrain'] = climate_heavyrain

    #temp = data['counts']
    #data = data.drop(['counts'], axis=1)
    #data['counts'] = temp
    #data.to_csv('./data/data_onehot/order_' + day)
    return data


def judge_climate(item, n):
    all_climate = ['Clear','Partly Cloudy','Scattered Clouds','Mostly Cloudy','Light Rain Showers',
                  'Light Rain','Unknown','Overcast','Rain','Rain Showers','Thunderstorm','Light Thunderstorms',
                  'Heavy Rain ']
    if str(item) == all_climate[n]:
        return 1
    else:
        return 0


def weather_process():

    data = pd.read_excel('./data/weather_data.xlsx', encoding='gbk')
    data = data[data.filter(regex='^(?!Unnamed)').columns]

    data['month_day'] = data['日期'].dt.day
    data['hour'] = data['日期'].dt.hour

    data = climate_to_onehot(data = data)

    data.drop(['名字','露点','海平面气压Hg','能见度Km','风向','风向描','瞬间风速','降雨量in'],axis = 1,inplace = True)

    new_name = {'日期':'date','温度':'temperature','湿度':'humitidy','风速':'wind speed'}

    data = data.rename(columns = new_name)

    data.to_csv('./data/weather_data.csv',index = False)
